home *** CD-ROM | disk | FTP | other *** search
- // Copyright ⌐ 1997 Mario M. Westphal
- // All Rights reserved
- // This source code is only intended as a supplement to the
- // Sort Solution user documentation and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding the
- // Sort Solution product.
- #include "stdafx.h"
- #include "sosox.h"
- #include "sosoxDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- //###########################################################################
- // C S o s o x D l g
- //###########################################################################
-
- /////////////////////////////////////////////////////////////////////////////
- //
- CSosoxDlg::CSosoxDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSosoxDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSosoxDlg)
- m_Edit = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
-
- m_Running = false;
- }
-
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CSosoxDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSosoxDlg)
- DDX_Control(pDX, IDC_PROGRESS_SORT, m_Progress_Sort);
- DDX_Control(pDX, IDC_PROGRESS_MERGE, m_Progress_Merge);
- DDX_Control(pDX, IDC_BTN_SORT, m_Btn_Sort);
- DDX_Control(pDX, IDC_BTN_BROWSE, m_Btn_Browse);
- DDX_Control(pDX, IDC_BTN_ABORT, m_Btn_Abort);
- DDX_Text(pDX, IDC_EDIT, m_Edit);
- DDX_Control(pDX, IDC_SORTSOL, m_SortSol);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CSosoxDlg, CDialog)
- //{{AFX_MSG_MAP(CSosoxDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BTN_ABORT, OnBtnAbort)
- ON_BN_CLICKED(IDC_BTN_BROWSE, OnBtnBrowse)
- ON_BN_CLICKED(IDC_BTN_SORT, OnBtnSort)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- BOOL CSosoxDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- m_Btn_Sort.EnableWindow(TRUE);
- m_Btn_Abort.EnableWindow(FALSE);
-
- m_Progress_Sort.SetRange(0,100);
- m_Progress_Merge.SetRange(0,100);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CSosoxDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CSosoxDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- BEGIN_EVENTSINK_MAP(CSosoxDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CSosoxDlg)
- ON_EVENT(CSosoxDlg, IDC_SORTSOL, 1 /* SortPercentage */, OnSortPercentageSortsol, VTS_I2)
- ON_EVENT(CSosoxDlg, IDC_SORTSOL, 2 /* MergePercentage */, OnMergePercentageSortsol, VTS_I2)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Avoid closing the dialog when a sort is running
- void CSosoxDlg::OnCancel()
- {
- if (!m_Running) CDialog::OnCancel();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Avoid closing the dialog when a sort is running
- void CSosoxDlg::OnOK()
- {
- if (!m_Running) CDialog::OnOK();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Open a file dialog to choose a profile
- void CSosoxDlg::OnBtnBrowse()
- {
- CFileDialog dlg(TRUE, _T("*.ssp"), NULL, OFN_OVERWRITEPROMPT,_T("Sort Solution Profiles (*.ssp)|*.ssp||"));
-
- if (dlg.DoModal() == IDOK) {
- m_Edit = dlg.GetPathName();
- UpdateData(FALSE);
- }
- }
-
-
-
- /////////////////////////////////////////////////////////////////////////////
- // This method loads the profile specified in the edit field and runs
- // the sort
- void CSosoxDlg::OnBtnSort()
- {
- m_Btn_Sort.EnableWindow(FALSE);
- m_Btn_Abort.EnableWindow(TRUE);
-
- m_Progress_Sort.SetPos(0);
- m_Progress_Merge.SetPos(0);
- m_Running = true;
-
- try {
-
- m_SortSol.LoadProfile(m_Edit);
- m_SortSol.Sort();
-
- // If we land here, no error occured and the sort
- // completed successfully
- CString msg;
- msg.Format(_T("Sort completed in %d seconds."),
- m_SortSol.GetStatsSortTime() + m_SortSol.GetStatsMergeTime());
-
- AfxMessageBox(msg,MB_ICONEXCLAMATION | MB_OK);
- }
- catch (CException* e)
- {
- e->ReportError(MB_ICONSTOP | MB_OK);
- e->Delete();
- m_Progress_Sort.SetPos(0);
- m_Progress_Merge.SetPos(0);
- }
-
- // The sort has finished
- m_Btn_Sort.EnableWindow(TRUE);
- m_Btn_Abort.EnableWindow(FALSE);
- m_Running = false;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CSosoxDlg::OnBtnAbort()
- {
- m_Running = false;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Handle the SortPercentage event
- void CSosoxDlg::OnSortPercentageSortsol(short Percentage)
- {
- m_Progress_Sort.SetPos(Percentage);
-
- // The user has aborted the sort. Set the "Aborted" property
- // of the Sort Solution control to TRUE
- if (!m_Running) m_SortSol.SetAborted(TRUE);
-
- // A CHEAP (and dirty) way to keep the app alive (and enables
- // us to press the abort button)
- // You should better use a second thread which manages the
- // sort process and keeps the main app alive...
- MSG msg;
- while (::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE)) {
- AfxGetApp()->PumpMessage();
- }
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Handle the MergePercentage event
- void CSosoxDlg::OnMergePercentageSortsol(short Percentage)
- {
- m_Progress_Merge.SetPos(Percentage);
-
- // The user has aborted the sort. Set the "Aborted" property
- // of the Sort Solution control to TRUE
- if (!m_Running) m_SortSol.SetAborted(TRUE);
-
-
- // A CHEAP (and dirty) way to keep the app alive (and enables
- // us to press the abort button)
- // You should better use a second thread which manages the
- // sort process and keeps the main app alive...
- MSG msg;
- while (::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE)) {
- AfxGetApp()->PumpMessage();
- }
- }
-
-
-